﻿namespace WordCloudClient.Common
{
    public class ControlHelper
    {
        /// <summary>
        /// 获取全选复选框是否勾选和批量删除按钮是否启用
        /// </summary>
        /// <param name="totalCount">总条目数</param>
        /// <param name="selectCount">选中的条目数</param>
        /// <returns></returns>
        public static Tuple<bool?, bool> GetBoolIsSelectAndIsBatch(int totalCount, int selectCount)
        {
            if (selectCount == 0)
            {
                return new Tuple<bool?, bool>(false, false);
            }
            else if (selectCount == totalCount)
            {
                return new Tuple<bool?, bool>(true, true);
            }
            else
            {
                return new Tuple<bool?, bool>(null, true);
            }
        }

        /// <summary>
        /// 获取总页数
        /// </summary>
        /// <param name="totalCount">总数量</param>
        /// <param name="pageSize">当前页面数量</param>
        /// <returns></returns>
        public static int GetPageTotals(int totalCount, int pageSize)
        {
            return totalCount % pageSize == 0 ? totalCount / pageSize : (totalCount / pageSize) + 1;
        }
        /// <summary>
        /// 获取页码相关信息
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页数量</param>
        /// <param name="totalPages">总页数</param>
        /// <param name="totalCount">总条数</param>
        /// <returns></returns>
        public static PaginationModel GetPaginationModel(int pageIndex, int pageSize, int totalPages, int totalCount)
        {
            int startCount = pageIndex * pageSize - pageSize + 1;
            int endCount = startCount + pageSize - 1;
            endCount = endCount <= totalCount ? endCount : totalCount;
            PaginationModel paginationModel = new()
            {
                PageSize = pageSize,
                TotalPages = totalPages,
                TotalCountInfo = $"{startCount}-{endCount}共{totalCount}条"
            };
            return paginationModel;
        }
    }
}
